const webpack = require('webpack');
const path = require('path');
const {entry, plugins, loaders} = require('./webpack.common');
const cfg = require('./config');

const hotLoader = [
    'react-hot-loader/patch',
    `webpack-dev-server/client?${cfg.devServer}`,
    'webpack/hot/only-dev-server'
];

module.exports = {
    resolve: {
        root: [path.resolve('../src/web')],
    },
    externals: cfg.libs.externals,
    cache: true,
    debug: true,
    devtool: 'source-map',
    entry: Object.assign(entry, {
        bundle: [
            ...hotLoader,
            cfg.src.web.entry
        ],
        vendor: [
            ...hotLoader,
            ...cfg.src.web.libs
        ]
    }),
    output: {
        publicPath: '/',
        path: cfg.run.web.path,
        filename: '[name].js',
        chunkFilename: '[name].js'
    },
    plugins: [
        ...plugins,
        new webpack.HotModuleReplacementPlugin(),
        new webpack.NoErrorsPlugin()
    ],
    module: loaders
};
